\label{ch:cost}
After we collected all the possible moves in the main algorithm we have to bring them in the right order so that the best move will be explored at first. This helps to find a solution faster.
We have to rank our moves to be able to order them. %We will at first play the first move and explore in this direction. If it's not working, we play the second, etc.
\\
To be able to rank our moves, we create at the beginning an array which has the same size as our board and which decide if a square is close to a goal or not.
If we just have one goal, we proceed like this : 
We compute for each square the distance between the square and the goal and we put this number on the ranking array.
\\
In the case that we have several goals, we create as many ranking arrays as the number of goals. Afterward, we create the final ranking array. That means we use for each square the minimum of all the ranking arrays for this board. Picture \ref{pic:rank1} shows the ranking array for the goal at (2,3). A wall is represented with a "X". The value for a wall in the sourcecode is 1000. 
\begin{figure}[htbp]
  \centering
  \fbox{
    \includegraphics[width=60mm]{ranking1.png}
  }
  \caption{Ranking array of a board for one goal}
  \label{pic:rank1}
\end{figure}




In picture \ref{pic:rank2} shows a representation of a final ranking array with several goals.
\begin{figure}[htbp]
  \centering
  \fbox{
	\includegraphics[width=60mm]{ranking2.png}
  }
  \caption{Ranking array of a board with several goals}
  \label{pic:rank1}
\end{figure} 

\includegraphics[width=60mm]{ranking3.png}


After we determinded this array, we are able to define the rank of a move. We imagine the positions of the boxes after this move and we add all values of the boxes's square. Therefore, we have a rank for all move and the best one is the lowest one because it's better to be close close to a goal. 
To move the boxes faster to a goal it is necessary to change the values of the ranking arry a bit. A goal should act like a magnet. 
%In fact, we changed a little this ranking array, because we want the goal is like a magnet. 
Moving a box which is close to the goal is better than moving a box which is far to the goal. To reache this we manipulate the array with the following specification.
If we call n the number in a square of an array, we change it by : 
$2pos(10-n)$        where $pos(x)$ is  : $x if x>0, 0 if x≤0$

That leads to a higher difference if we move a box which is closer to the goal than a box which is further.% With this ranking array, we take the highest rank.